class PurchasesController < ApplicationController
  # GET /purchases
  # GET /purchases.xml
  def index
    @purchases = Purchase.find(:all)

    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @purchases.to_xml }
    end
  end

  # GET /purchases/1
  # GET /purchases/1.xml
  def show
    @purchase = Purchase.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @purchase.to_xml }
    end
  end

  # GET /purchases/new
  def new
    @purchase = Purchase.new
  end

  # GET /purchases/1;edit
  def edit
    @purchase = Purchase.find(params[:id])
  end

  # POST /purchases
  # POST /purchases.xml
  def create
    @purchase = Purchase.new(params[:purchase])

    respond_to do |format|
      if @purchase.save
        flash[:notice] = 'Purchase was successfully created.'
        format.html { redirect_to purchase_url(@purchase) }
        format.xml  { head :created, :location => purchase_url(@purchase) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @purchase.errors.to_xml }
      end
    end
  end

  # PUT /purchases/1
  # PUT /purchases/1.xml
  def update
    @purchase = Purchase.find(params[:id])

    respond_to do |format|
      if @purchase.update_attributes(params[:purchase])
        flash[:notice] = 'Purchase was successfully updated.'
        format.html { redirect_to purchase_url(@purchase) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @purchase.errors.to_xml }
      end
    end
  end

  # DELETE /purchases/1
  # DELETE /purchases/1.xml
  def destroy
    @purchase = Purchase.find(params[:id])
    @purchase.destroy

    respond_to do |format|
      format.html { redirect_to purchases_url }
      format.xml  { head :ok }
    end
  end
end
